package com.wsh.controller.sys;

import com.wsh.utils.JsonResult;
import com.wsh.dto.sys.DepartmentDto;
import com.wsh.sys.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
* @author 王思涵
* @date 2020-03-14
*/
@Api(tags = "部门管理管理")
@RestController
@RequestMapping("/sys/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/list")
    @PreAuthorize("@el.check('department:list')")
    @ApiOperation(value = "部门管理列表")
    public Object list(DepartmentDto departmentDto) {
        return JsonResult.success(departmentService.getList(departmentDto));
    }

    @GetMapping("/getById")
    @PreAuthorize("@el.check('department:getById')")
    @ApiOperation(value = "查询部门管理")
    public Object getById(@RequestParam String formId) {
        return JsonResult.success(departmentService.queryVo(formId));
    }

    @PostMapping("/save")
    @PreAuthorize("@el.check('department:save')")
    @ApiOperation(value = "保存部门管理")
    public Object save(@Valid @RequestBody DepartmentDto departmentDto) {
        return JsonResult.success(departmentService.saveDepartment(departmentDto));
    }

    @PostMapping("/del")
    @PreAuthorize("@el.check('department:del')")
    @ApiOperation(value = "删除部门管理")
    public Object del(@RequestParam String formId) {
        return JsonResult.success(departmentService.removeById(formId));
    }

    @GetMapping("/tree")
    @PreAuthorize("@el.check('department:tree')")
    @ApiOperation(value = "部门树结构")
    public Object tree() {
        return JsonResult.success(departmentService.departTree("0"));
    }

}
